import { CopyControllerBase } from "./CopyControllerBase";
import { CopyCountDownLabel } from "../CopyCountDownLabel";
import { DefendSkillPropListPanel } from "../defend/DefendSkillPropListPanel";
import { SixtyDefenceCopyView } from "../sixtyDefence/SixtyDefenceCopyView";
import { NetDispatcher } from "../../../../mvc/core/NetDispatcher";
import { ECmdCell } from "../../../../../Message/Command/ECmdCell";
import { EPublicCommand } from "../../../../../Message/Command/EPublicCommand";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { EventName } from "../../../mvc/EventName";
import { TCopy } from "../../../../../Message/Db/Tables/TCopy";
import { ECopyType } from "../../../../../Message/Public/ECopyType";
import { SCopyMsgInfo } from "../../../../../Message/Public/SCopyMsgInfo";
import { Global } from "../../../../../com/gengine/global/Global";
import { MsgManager } from "../../../manager/MsgManager";
import { Language } from "../../../../../extend/language/Language";
import { MessageBlock } from "../../../../../Framework/MQ/MessageBlock";
import { SSeqPlayerItem } from "../../../../../Message/Public/SSeqPlayerItem";
import { SCopyDefenceInfo } from "../../../../../Message/Public/SCopyDefenceInfo";
import { DataEvent } from "../../../events/DataEvent";
import { GameProxy } from "../../../mvc/GameProxy";
type int = number;
//class DefenceCopyController
    
    export  class DefenceCopyController extends CopyControllerBase
    {
        constructor()
        {
            super();
            return;
        }

        public get countDownLabel(): CopyCountDownLabel
        {
            if (!this._countDownLabel) 
            {
                this._countDownLabel = new CopyCountDownLabel();
            }
            return this._countDownLabel;
        }

        public get defendPropPanel(): DefendSkillPropListPanel
        {
            if (!this._defendPropPanel) 
            {
                if (cache.copy.isInKingCopy(cache.copy.copyInfo)) 
                {
                    this._defendPropPanel = new DefendSkillPropListPanel(6, false, "", "", true);
                }
                else 
                {
                    this._defendPropPanel = new DefendSkillPropListPanel(5);
                }
            }
            return this._defendPropPanel;
        }

        public get sixtyDefenceCopyView(): SixtyDefenceCopyView
        {
            if (!this._sixtyDefenceCopyView) 
            {
                this._sixtyDefenceCopyView = new SixtyDefenceCopyView();
            }
            return this._sixtyDefenceCopyView;
        }

        protected /* override */ initServer(): void
        {
            NetDispatcher.addCmdListener(ECmdCell._ECmdCellPushDefenseItemList, this.onReceiveDefenseItemList);
            NetDispatcher.addCmdListener(EPublicCommand._ECmdPublicCopyDefeceInfo, this.onReceive60CopyDefenceInfo);
            return;
        }

        protected /* override */ addListener(): void
        {
            Dispatcher.addEventListener(EventName.Copy60DefenceUpgrade, this.on60DefenceUpgradeBoss);
            Dispatcher.addEventListener(EventName.Copy60DefenceUse, this.on60DefenceUseBoss);
            return;
        }

        protected /* override */ removeListener(): void
        {
            Dispatcher.removeEventListener(EventName.Copy60DefenceUpgrade, this.on60DefenceUpgradeBoss);
            Dispatcher.removeEventListener(EventName.Copy60DefenceUse, this.on60DefenceUseBoss);
            return;
        }

        public /* override */ enterCopy(arg1: TCopy): void
        {
            super.enterCopy(arg1);
            this.showDefendPropPanel();
            return;
        }

        public /* override */ leaveCopy(): void
        {
            super.leaveCopy();
            if (this._countDownLabel && !this._countDownLabel.isHide) 
            {
                this._countDownLabel.hide();
            }
            if (this._defendPropPanel && !this._defendPropPanel.isHide) 
            {
                this._defendPropPanel.hide();
                this._defendPropPanel = null;
            }
            if (this._sixtyDefenceCopyView && !this._sixtyDefenceCopyView.isHide) 
            {
                this._sixtyDefenceCopyView.hide();
            }
            return;
        }

        public updateRingBottleExp(): void
        {
            if (!copy) 
            {
                return;
            }
            if (copy.copyType == ECopyType._ECopyDefense && !cache.copy.isInKingCopy(copy)) 
            {
                this.countDownLabel.updateRingBottleExp();
            }
            else if (copy.copyType == ECopyType._ECopy60Defense) 
            {
                this.sixtyDefenceCopyView.updateRingBottleExp();
            }
            return;
        }

        public updateRing(arg1: SCopyMsgInfo): void
        {
            if (!copy) 
            {
                this._ringInfo = arg1;
                return;
            }
            if (copy.copyType == ECopyType._ECopyDefense && !cache.copy.isInKingCopy(copy)) 
            {
                this.countDownLabel.setTimeLabel_Ring(arg1.num1, arg1.num2);
            }
            else if (copy.copyType == ECopyType._ECopy60Defense) 
            {
                this.sixtyDefenceCopyView.setTimeLabel_Ring(arg1.num1, arg1.num2, "");
            }
            return;
        }

        public updateBossRefresh(arg1: SCopyMsgInfo): void
        {
            if (!copy) 
            {
                this._bossRefreshInfo = arg1;
                return;
            }
            if (copy.copyType == ECopyType._ECopyDefense && !cache.copy.isInKingCopy(copy)) 
            {
                this.countDownLabel.setTimeLabel_Ring(arg1.num1, arg1.num2, CopyCountDownLabel.BOSS_REFRESH);
            }
            else if (copy.copyType == ECopyType._ECopy60Defense) 
            {
                this.sixtyDefenceCopyView.setTimeLabel_Ring(arg1.num1, arg1.num2, CopyCountDownLabel.BOSS_REFRESH);
            }
            return;
        }

        /* internal  */showDefendPropPanel(): void
        {
            if (!copy) 
            {
                return;
            }
            if (cache.copy.isInDefendCopy()) 
            {
                this.defendPropPanel.show(Global.stage.stageWidth - 485, Global.stage.stageHeight - 175);
                if (!cache.copy.isInKingCopy(copy)) 
                {
                    this.countDownLabel.show();
                    this.countDownLabel.updateRingBottleExp();
                    if (this._ringInfo) 
                    {
                        this.countDownLabel.setTimeLabel_Ring(this._ringInfo.num1, this._ringInfo.num2);
                        this._ringInfo = null;
                    }
                }
                this.stageResize();
            }
            else if (cache.copy.isIn60DefendCopy()) 
            {
                this.sixtyDefenceCopyView.show();
                this.sixtyDefenceCopyView.setCopyCode(copy.code);
                this.sixtyDefenceCopyView.updateRingBottleExp();
                if (cache.copy.sixtyDefenceCopyInfo) 
                {
                    this.sixtyDefenceCopyView.updateBuildingInfo(cache.copy.sixtyDefenceCopyInfo);
                }
                if (this._ringInfo) 
                {
                    this.sixtyDefenceCopyView.setTimeLabel_Ring(this._ringInfo.num1, this._ringInfo.num2, "");
                    this._ringInfo = null;
                }
                MsgManager.showTaskTarget(Language.getString(60391), 15);
                this.stageResize();
            }
            return;
        }

        /* internal  */onReceiveDefenseItemList(arg1: MessageBlock): void
        {
            var loc1=arg1.messageBase as SSeqPlayerItem;
            this.defendPropPanel.setPropListData(loc1.playerItem);
            return;
        }

        /* internal  */onReceive60CopyDefenceInfo(arg1: MessageBlock): void
        {
            var loc1=arg1.messageBase as SCopyDefenceInfo;
            cache.copy.sixtyDefenceCopyInfo = loc1;
            if (copy) 
            {
                this.sixtyDefenceCopyView.setCopyCode(copy.code);
                this.sixtyDefenceCopyView.updateBuildingInfo(cache.copy.sixtyDefenceCopyInfo);
            }
            return;
        }

        /* internal  */on60DefenceUpgradeBoss(arg1: DataEvent): void
        {
            var loc1=arg1.data as int;
            GameProxy.copy.useSocoreInDefenseCopy(1, loc1);
            return;
        }

        /* internal  */on60DefenceUseBoss(arg1: DataEvent): void
        {
            var loc1=arg1.data as int;
            GameProxy.copy.useSocoreInDefenseCopy(2, loc1);
            return;
        }

        public /* override */ stageResize(): void
        {
            if (this._countDownLabel && !this._countDownLabel.isHide) 
            {
                this._countDownLabel.stageResize();
            }
            if (this._sixtyDefenceCopyView && !this._sixtyDefenceCopyView.isHide) 
            {
                this._sixtyDefenceCopyView.stageResize();
            }
            if (this._defendPropPanel) 
            {
                if (this._defendPropPanel.x + 485 > Global.stage.stageWidth) 
                {
                    this._defendPropPanel.x = Global.stage.stageWidth - 485;
                }
                if (this._defendPropPanel.y + 175 > Global.stage.stageHeight) 
                {
                    this._defendPropPanel.y = Global.stage.stageHeight - 175;
                }
            }
            return;
        }

        /* internal */ /* var */_countDownLabel: CopyCountDownLabel;

        /* internal */ /* var */_defendPropPanel: DefendSkillPropListPanel;

        /* internal */ /* var */_sixtyDefenceCopyView: SixtyDefenceCopyView;

        /* internal */ /* var */_ringInfo: SCopyMsgInfo;

        /* internal */ /* var */_bossRefreshInfo: SCopyMsgInfo;
    }
